﻿using AntUnion.FrameWork.Model.Models;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AntUnion.FrameWork.Web.Areas.Console.Controllers
{
    public class ContactController : BaseController
    {
        private readonly _antunionContext _context;

        private readonly IWebHostEnvironment _hostingEnv;
        public ContactController(_antunionContext context, IWebHostEnvironment env) : base(context, env)
        {
            _context = context;
            _hostingEnv = env;
        }

        public IActionResult Index()
        {
            string cont = "";
            TbSystemConfig contactUs = _context.TbSystemConfigs.FirstOrDefault(k => k.MenuName == "contact_us");
            if(contactUs != null)
            {
                cont = contactUs.Value;
            }
            ViewBag.Cont = cont;
            return View();
        }


        [HttpPost]
        public JsonResult UpdatecontactUs(string Content)
        {
            Result res = new Result();
            try
            {
                TbSystemConfig contactUs = _context.TbSystemConfigs.FirstOrDefault(k => k.MenuName == "contact_us");
                if (contactUs != null)
                {
                    contactUs.Value = Content;
                }
                res.Code = 0;
                res.Data = _context.SaveChanges();
            }
            catch (Exception ex)
            {
                res.Code = 1;
                res.Msg = ex.Message;
            }
            return new JsonResult(res);
        }
    }
}
